// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.css.conf with an alias.

import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import VueDND from 'awe-dnd'
import lodash from 'lodash'
import VCharts from 'v-charts'
import Site from "./site/Site"

//引入 view-design
import ViewUI from 'view-design';

//可通过覆盖 view-design 的 css 覆盖默认的主题
// import '../theme/theme_05.less'; //05后台主题
// import '../theme/theme_tiy.less'; //主站后台主题
// import '../theme/theme_baba.less'; //仿牌站后台主题
import '../theme/theme_wow.less'; //仿牌站后台主题

// 引入各个功能的 URL 定义
import AURLS from  './pages/js/baseUrl'

//引入 axios 网络请求框架
import  axios from './api/utils/AxiosUtils'

//引入所有的网络请求 API 接口定义
import ApiAll from './api/Api'

//权限管理
import './authority/Autority'

Vue.use(VCharts)

//公共的prototype声明
import  './base/prototypes'
import './utils/PrototypeUtils'

import vueQuillEditor from 'vue-quill-editor'
Vue.use(vueQuillEditor);

import VueTimers from 'vue-timers'

import VueClipboard  from 'vue-clipboard2'

Vue.use( VueClipboard )

Vue.use(VueTimers)

//将一些常用的内容绑定到 prototype 上,以便随时随地无需引用的使用.

Vue.prototype._ = lodash;
Vue.prototype.$isDebug = ApiAll.isDebug;
Vue.prototype.$http = axios;
Vue.prototype.$site = Site;

Vue.prototype.$apiRole = new ApiAll.ApiRole();
Vue.prototype.$apiAnalysis = new ApiAll.ApiAnalysis();
Vue.prototype.$apiImage = new ApiAll.ApiImage();
Vue.prototype.$apiMain = new ApiAll.ApiMain();
Vue.prototype.$apiOrder = new ApiAll.ApiOrder();
Vue.prototype.$apiNewOrder = new ApiAll.ApiNewOrder();
Vue.prototype.$apiOther = new ApiAll.ApiOther();
Vue.prototype.$apiProduct = new ApiAll.ApiProduct();
Vue.prototype.$apiUser = new ApiAll.ApiUser();
Vue.prototype.$apiPlugin = new ApiAll.ApiPlugin();
Vue.prototype.$apiClassification = new ApiAll.ApiClassification();
Vue.prototype.$apiCoupon= new ApiAll.ApiCoupon();
Vue.prototype.$apiChat= new ApiAll.ApiChat();
Vue.prototype.$apiStand= new ApiAll.ApiStand();
Vue.prototype.$apiEmail = new ApiAll.ApiEmail();
Vue.prototype.$ApiProductSource = new ApiAll.ApiProductSource();
Vue.prototype.$apiImpProduct = new ApiAll.ApiImpProduct();
Vue.prototype.$store = store;
Vue.prototype.$apiBlog = new ApiAll.ApiBlog();;

Vue.use(axios);
Vue.use(ViewUI);
//拖拽排序插件
Vue.use(VueDND);

Vue.config.productionTip = false;

// 配置 view-design中顶部进度条的样式(颜色/粗细等)
ViewUI.LoadingBar.config({
  color: '#f3f3f6',
  failedColor: '#f0ad4e',
  height: 3
});

// 拦截器. 每个路由页面开始前启动进度条,并判断是否已经登录; 结束时,关闭进度条.
var self = this;
router.beforeEach((to, from, next) => {
  // console.log("路由 to = ",to.path," from = ",from.path,' 权限=',to.path!=='/index');
  ViewUI.LoadingBar.start();
  if (!store || store.getters.userInfo === null) {
    next();
    router.replace(AURLS.ALogin);
  } else if (!Vue.prototype.$authority(to.path) && (to.path !== '/login') && (to.path !== '/index') && (to.path !== '/work/dashboard') && (to.path !== '/') ) {
    next();
    // router.replace(AURLS.AError);
  } else {
    next();
  }
});
router.afterEach((to, from, next) => {
  ViewUI.LoadingBar.finish();
});

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: {App}
});

